<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <script src="../jQuery/jquery-1.11.2.js"></script>
    <script src="../layui/layui.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/font.css">
    <style>::-webkit-scrollbar{display: none;}</style>
</head>
<body>
<blockquote class="layui-elem-quote news_search">
    <table id="bg" lay-filter="bg"></table>

<script id="gjl" type="text/html">
<div class="layui-form-item">
    <!--头部工具栏-->
    <div class="layui-btn-container layui-input-inline" style="margin-left: 50px">
        <button class="layui-btn layui-btn-danger" lay-event="scs">
            <i class="layui-icon">&#xe640;</i>批量删除
        </button>
        <button class="layui-btn layui-btn-normal" lay-event="zj" style="margin-left: 130px;margin-top: -78px;">
            <i class="layui-icon">&#xe654;</i>添加角色
        </button>
    </div>
</div>
</script>
<div style="display: none;" id="qxdhk">
    <div id="jj"></div>
</div>
<div style="display: none;" id="dhk">
    <form style="margin-top: auto;padding-top: 50px" class="layui-form" id="zjdhk" method="POST" lay-skin="line" lay-filter="dhk">
        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">id：</label>
            <div class="layui-input-inline">
                <input type="text" name="roleId" placeholder="请输入角色名" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色名：</label>
            <div class="layui-input-inline">
                <input type="text" name="roleName" lay-verify="required" placeholder="请输入角色名" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-bg-blue" id="tjs" lay-submit lay-filter="formSave">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
    <script id="gj" type="text/html">
        <button  class="layui-btn layui-btn-sm layui-btn-danger" lay-event="sc"><i class="layui-icon layui-icon-delete"></i>删除</button>
        <button  class="layui-btn layui-btn-sm  layui-btn-normal" lay-event="xg"><i class="layui-icon layui-icon-edit"></i>修改角色名</button>
        <button  class="layui-btn layui-btn-sm  layui-btn-normal" lay-event="qx"><i class="layui-icon layui-icon-slider"></i>设置权限</button>
    </script>
<script>
    layui.use(['table','layer','form','transfer'],function () {
     var table=layui.table;
        var layer=layui.layer;
        var form=layui.form;
        var tr=layui.transfer;

        table.render({
            elem: '#bg',//表格对象
            url:"/fc/sy",//"json/emplayui.json",//实际使用servlet路径(后台服务路径)
            page: true,//分页
            method:'GET',//提交方式
            /*height:630,*/
            toolbar: '#gjl',//表格上方普通工具栏
            limit:15,//每页行数
            height:740,
            cols:[[
                {checkbox:true},
                {field:"roleName",title:"角色名",sort:true,align:"center"},
                {fixed: 'right', title:'操作', toolbar: '#gj'}
            ]],
            limits: [5, 10,20,30,50]
        });
        var ms="";
        form.on("submit(formSave)",function (msg) {
            $.ajax({
                url:"/fc/sy",
                method: ms,
                data:JSON.stringify(msg.field),
                contentType:"application/json;charset=utf-8",
                success:function (sj) {
                    if(sj=="cg"){
                        layer.closeAll();
                        location.reload();
                    }else{
                        alert("失败");
                    }
                }
            });
        })
        table.on("toolbar(bg)",function (msg) {
                var che=table.checkStatus(msg.config.id);

            if(msg.event=="scs"){
                var ss="";
                for (var i=0;i<che.data.length;i++){
                    ss+=che.data[i].roleId+",";
                }
                $.ajax({
                    url:"/fc/sys/"+ss,
                    method: "put",
                    success:function (sj) {
                        if(sj=="cg"){
                            layer.closeAll();
                            location.reload();
                        }else{
                            alert("失败");
                        }
                    }

                });
            }else{

                layer.open({
                    title:"<span style='color:white' align='center'><i class='layui-icon'>&#xe61f;</i> 添加角色</span>",
                    type: 1,//外部页面为2，内部层1
                    area: ['30%', '30%'],
                    fix: false,
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    skin: 'layui-layer-lan',
                    content:$("#dhk").html()
                });
                ms="post";
            }

        });
        table.on("tool(bg)",function (msg) {
            var data=msg.data;
            if(msg.event=="sc"){
                layer.confirm('你确定删除', function(index){
                    $.ajax({
                        url:"/fc/sy/"+data.roleId,
                        method: "delete",
                        success:function (sj) {
                            if(sj=="cg"){
                                layer.closeAll();
                                msg.del();
                            }else{
                                alert("失败");
                            }
                        }

                    });
                });

            }else if(msg.event=="qx"){
                $.ajax({
                    url:"/fc/qx/"+data.roleId,
                    method: "put"
                });
                layer.open({
                    title:"<span style=\'color:white\' align=\'center\'><i class=\'layui-icon\'>&#xe6b2;</i>设置权限</span>",
                    type: 2,//外部页面为2，内部层1
                    area: ['40%', '70%'],
                    skin: 'layui-layer-lan',
                    content:['Fun.html','no']

                });

            }else{
                layer.open({
                    title:"<span style=\'color:white\' align=\'center\'><i class=\'layui-icon\'>&#xe6b2;</i>修改角色</span>",
                    type: 1,//外部页面为2，内部层1
                    area: ['30%', '30%'],
                    fix: false,
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    skin: 'layui-lay er-lan',
                    content:$("#dhk").html()
                });
                ms="put";
             form.val("dhk",{
                 roleName:data.roleName,
                 roleId:data.roleId
             });
            }
        });
    });
</script>
</body>
</html>